package com.lx.javasunmmrize.prototype;

/**
 * @Description 克隆羊问题测试1,直接new N个对象赋值
 *
 *      浅拷贝测试，对象属性的hashcode一致，即克隆只是把对象属性的引用进行克隆，最终还是指向被克隆的
 *      对象属性的内存空间
 *
 * @Author lx
 * @Date 2021/2/26 23:32
 **/
public class PrototyoeTest01 {
    public static void main(String[] args) throws CloneNotSupportedException {
        //最原始的方法，不推荐使用
//        Cat c1 = new Cat("tom","white");
//        Cat c2 = new Cat("tom","white");
//        Cat c3 = new Cat("tom","white");
//
//        System.out.println(c1);
//        System.out.println(c2);
//        System.out.println(c3);

        Cat c = new Cat("tom","white");
        Cat c1 = new Cat("tom","white");
        c1.setFriend(c);
        Cat c2 = (Cat) c1.clone();
        Cat c3 = (Cat) c1.clone();
        System.out.println(c1+","+c1.getFriend().hashCode());
        System.out.println(c2+","+c2.getFriend().hashCode());
        System.out.println(c2+","+c2.getFriend().hashCode());
    }
}
